import { Component, OnInit, Input } from '@angular/core';
import { UserService } from 'src/app/service/user.service';
import { YearawardService } from '../yearaward.service';
import { BaseService } from 'src/app/service/base.service';
import { UtilsService } from 'src/app/service/utils.service';
@Component({
  selector: 'app-male',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.scss'],
})
export class MaleComponent implements OnInit {
  @Input() timeConfig: any[] = [];
  /* ___ _ ___ */
  public deployUrl: string; /* 资源地址前缀 */
  /* ___ _ ___ */
  public tabs: EndYear.ITAB[] = [
    {
      status: 1,
      key: 1,
      type: 29,
      stageId: undefined,
      startTime: undefined,
      endTime: undefined,
    },
  ]; /* tabs */
  /* ___ _ ___ */
  public curTabKey = 1; /* 当前tab 0晋级赛 1决赛 */

  constructor(
    private userService: UserService,
    private yearawardService: YearawardService,
    private baseService: BaseService,
    private utilsservice: UtilsService
  ) {}

  ngOnInit(): void {
    // 获取
    this.deployUrl = this.userService.getDeployUrl();
    //
    this.checkChildren();
  }

  /**
   * @param tab 当前tab
   * @description: 切换tab
   */
  onTabClick(tab) {
    const { status, key } = tab;
    if (status === 1) {
      // 未开始
      this.baseService.showToast('活动暂未开始', 1500);
    } else {
      this.curTabKey = key;
    }
  }

  /**
   * 计算当前活动阶段
   */
  public checkChildren() {
    const children = this.baseService.useStatusWithTargetTypes(
      this.timeConfig,
      25,
      28
    );
    this.tabs = children;
    console.log('v2v2=>', this.tabs);

    for (let index = 0; index < children.length; index++) {
      const child = children[index];
      if (
        child.status === 2 ||
        (child.status === 1 && index === 0) ||
        (child.status === 3 && index === children.length - 1)
      ) {
        this.curTabKey = child.key;
        break;
      }
    }
  }
}
